//////////////////////////////////////////////////////////////////////
//!\file FileSystemManager.hpp
//!\brief Does filesearch and all other file processings in a separate thread.
//!\author timmsusa@googlemail.com
//////////////////////////////////////////////////////////////////////

#ifndef FILESYSTEMMANAGER_HPP
#define FILESYSTEMMANAGER_HPP

#include <QObject>
#include <QDir>
#include <QString>
#include "FlacTrack.hpp"
#include <QVector>
#include <QFileInfo>
#include <QSet>
//#include <QSystemStorageInfo>
#include "FileStorageWorkData.hpp"
#include "Persistence.hpp"
#include "AlbumDataModel.hpp"
#include "ThreadFlacScanner.hpp"
#include "ThreadRemoveFiles.hpp"
#include "ThreadCopyFiles.hpp"


class FileSystemManager : public QObject//, public FlacMetadataManager
{
    Q_OBJECT
public:
    FileSystemManager(QObject *parent = 0);
    ~FileSystemManager();
private:
    void compareFlacLists();
    bool isAlbumDuplicate(const Album& updateAlbum, const Album& collAlbum);
    void scanDirsToMusicCollection(const QDir& dir);
    void scanDirsToUpdateCollection(const QDir& dir);
    void createAndConnectThreadCollectionFlacScan(const QDir &dir);
    void createAndConnectThreadUpdateFlacScan(const QDir &dir);
    void createAndConnectThreadCopyFiles(const QStringList &src,const QStringList &dest);
    void createAndConnectThreadRemoveFiles(const QStringList &path);
    void destroyThreadCollectionFlacScan();
    void destroyThreadUpdateFlacScan();
    void destroyThreadCopyFiles();
    void destroyThreadRemoveFiles();

signals:
    void sigFlacFound(QString file);
    void sigFolderFound(Album album);
    void sigSearchInMusicCollectionFinished();
    void sigSearchInFileIncomingFinished();
    void sigFlacListComparisonFinished(QVector < Album > diffList);
    void sigCopyProgress(int cnt, QString path);
    void sigCopyProgressFinished(bool wasSuccessful);
    void sigRemoveProgress(int cnt, QString path);
    void sigRemoveRunFinished(bool wasSuccessful);
    void sigEnableDeepScan(bool enable);
    void sigStopScanMusicCollection();
    void sigStopScanUpdateCollection();
    void sigInitMusicCollectionByPath(QString path);
    void sigInitUpdateCollectionByPath(QString path);
    void sigStopScanner();
    void sigStopCopy();

public slots:
    void slotSearchInMusicCollection(QString path);
    void slotSearchInFileIncoming(QString path);
    void slotCompareFlacLists();
    // DEPRECATED
    //void slotRemoveDir(const QString & dirName);
    void slotRemoveFromFileSystem(QStringList pathList);
    //void slotCopy(bool isFile, QString source, QString dest);
    void slotCopyAllFolderTo(QStringList srcPaths, QStringList destPaths);
    void slotResetCopyProgressCounter();
    void slotResetRemoveProgressCounter();
    void slotEnableDeepScan(bool enable);
    void slotInitOfMusicCollectionModelFinished();
    void slotInitOfUpdateCollectionModelFinished();
   // void slotStopScanMusicCollection();
   // void slotStopScanUpdateCollection();

private:
    Persistence         m_Persistence;
    bool                m_DeepScanEnabled;
    //FileStorageWorkData *m_pFileStorage;
    QVector < Album > m_DiffCollection;
    int             m_CopyProgressCount;
    int             m_RemoveProgressCount;
    ThreadFlacScanner *m_pScannerMusicCollection;
    ThreadFlacScanner *m_pScannerUpdateCollection;
    ThreadRemoveFiles *m_pThreadRemoveFiles;
    ThreadCopyFiles   *m_pThreadCopyFiles;
};

#endif // FILESYSTEMMANAGER_HPP
